#include <stdio.h>
void swap(int * a, int * b)
{
    int temp = *a;
    (*a) = (*b);
    (*b) = temp;
}
void printArray(int * x, int n)
{
    int i;
    for (i = 0; i < n; i ++)
	{ printf("%8d", x[i]); 	}
    printf("\n");
}
int main(int argc, char * argv[])
{
    int x[] = {6, 7, 3, 2, 0, 9, -4, 1};
    int n = sizeof(x) / sizeof(int);
    printArray(x, n);
    int ind1, ind2, minInd;
    for (ind1 = 0; ind1 < n - 1; ind1 ++)
	{
	    minInd = ind1;
	    for (ind2 = ind1 + 1; ind2 < n; ind2 ++)
		{
		    if (x[minInd] > x[ind2])
			{ minInd = ind2; }
		}
	    if (minInd != ind1)
		{ 
		    printf("\nind1 = %d, minInd = %d, x[ind1] = %d, x[minInd] = %d\n", 
			   ind1, minInd, x[ind1], x[minInd]);
		    swap(&x[ind1], &x[minInd]); 
		    printArray(x, n); 
		}
	}
    printArray(x, n);
    return 0;
}
